package tech.edwardvan.springbootdemo.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.EventPublishingRunListener;
import org.springframework.boot.context.event.SpringApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;

/**
 * 应用事件监听器
 * <p>
 * 通过 spring.factories 配置方式添加
 * <p>
 * 执行:{@link EventPublishingRunListener} to publish {@link SpringApplicationEvent}s
 *
 * @author EdwardVan
 */
@Slf4j
public class DemoApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {

    @Override
    public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
        log.warn("应用事件监听器,通过spring.factories配置方式添加");
        log.info("通过应用事件监听器获取server.port:{}", event.getEnvironment().getProperty("server.port"));
    }
}
